#! /bin/sh -vx
# Copyright 2017-2018 Karl Berry <tex-live@tug.org>
# Copyright 2015 Peter Breitenlohner <tex-live@tug.org>
# You may freely use, modify and/or distribute this file.

BinDir=${BinDir:-.}
ExeExt=${ExeExt:-}
_msxlint=$BinDir/msxlint$ExeExt

# pre-generated test results in the repository are stored in LF
# but the output might be written in CRLF on some platform.
# if 'diff --strip-trailing-cr' is available, exploit it.
# (useful for tests on win32 binaries run on MSYS shell)
DIFF="diff"
$DIFF --strip-trailing-cr $0 $0 \
  && DIFF="diff --strip-trailing-cr" || echo

LC_ALL=C; export LC_ALL;  LANGUAGE=C; export LANGUAGE

echo && echo "*** msxlint --help"
$_msxlint --help || exit 1

echo && echo "*** msxlint --version"
$_msxlint --version || exit 2

: ${testsrc:=$srcdir/tests}

echo && echo "*** msxlint -d tests/badtest"
$_msxlint -d $testsrc/badtest && exit 3

echo && echo "*** msxlint tests/linttest >linttest.out1"
$_msxlint $testsrc/linttest | sed '/^This/,/^Processing/d' >linttest.out1 || exit 4

echo && echo "*** diff tests/linttest.out linttest.out1"
$DIFF $testsrc/linttest.out linttest.out1 || exit 5

echo && echo "*** cat tests/linttest.tex | msxlint >linttest.out2"
cat $testsrc/linttest.tex | $_msxlint | sed '/^This/,/^Processing/d' >linttest.out2 || exit 6

echo && echo "*** diff tests/linttest.out linttest.out2"
$DIFF $testsrc/linttest.out linttest.out2 || exit 7

